import React from 'react';
import '../css/login.css';
import { Redirect } from 'react-router'
import { observer } from 'mobx-react'
import { Form, Icon, Input, Button, message, Row, Col } from 'antd';

const { TextArea } = Input;
import 'antd/lib/message/style'
import 'antd/lib/form/style'
import 'antd/lib/icon/style'
import 'antd/lib/input/style'
import 'antd/lib/button/style'
import 'antd/lib/row/style'
import 'antd/lib/col/style'

import PostService from '../service/post'

@observer
export default class Pub extends React.Component {
    constructor(props) {
        super(props);
        this.service = new PostService();
    }
    handleSubmit(event) {
        event.preventDefault()
        let fm = event.target
        this.service.pub(fm[0].value, fm[1].value)
    }
    render() {
        if (this.service.semsg) {
            message.success("上传成功", 3, () => this.service.semsg = " ")
            return <Redirect to="/getall" />
        }
        if (this.service.famsg) {
            message.error("未登陆，请登录！", 3, () => this.service.famsg = " ")
            return <Redirect to='/login' />
        }
        return (
            <Form onSubmit={this.handleSubmit.bind(this)} >
                <Form.Item label="标题" wrapperCol={{ span: 20 }} labelCol={{ span: 2 }}>
                    <Input />
                </Form.Item>
                <Form.Item label="内容" wrapperCol={{ span: 20 }} labelCol={{ span: 2 }}>
                    <TextArea rows={28} />
                </Form.Item>
                <Form.Item wrapperCol={{ span: 4, offset: 10 }}>
                    <Button type="primary" htmlType="submit"  >发布</Button>
                </Form.Item>
            </Form>


        )
    }
}